<?php
class Training_CurrencyController extends Zendvn_Controller_Action{
    
    public function init() {
        parent::init();
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender();
    }
    
    public function indexAction() {
        $options = array(
                        'value'=>11111222100000123.012345,//1.000000,000
                        'position'=>  Zend_Currency::RIGHT,
                        'format'=>  '#,#####0.##0',
//                        'display'=>  Zend_Currency::USE_SHORTNAME,
                        'precision'=> 3,
                        'name'=> 'Đô la Việt Nam',
                        'currency'=> 'VND-1',
                        'symbol'=> 'VND',
                        );
        $locale = 'vi_VN';
        $currency = new Zend_Currency($options, $locale);
        
        echo $currency;
        
        echo '<pre>';
        print_r($currency);
        echo '<pre>';
    }
    
    public function index2Action() {
        $currency = new Zend_Currency();
        $value = 12000;
        $options = array();
        echo $currency->toCurrency($value, $options);
    }
    
    public function index3Action() {
        $currency = new Zend_Currency('en_US');
        $options = array(
                        'value'=>11111222100000123.012345,//1.000000,000
                        'position'=>  Zend_Currency::RIGHT,
                        'format'=>  '#,#####0.##0',
//                        'display'=>  Zend_Currency::USE_SHORTNAME,
                        'precision'=> 3,
                        'name'=> 'Đô la Việt Nam',
                        'currency'=> 'VND-1',
                        'symbol'=> 'VND',
                        'locale'=> 'vi_VN',
                        );
        $currency->setFormat($options);
        echo $currency->toCurrency(1000);
    }
    
    public function addAction() {
        $numberA = 100.45;
        $numberB = 2300;
        $options = array('precision'=>3);
        
        $currency = New Zend_Currency($options);
        echo '<br>' . $currency->setValue($numberA);
        
//        echo '<br>Ket qua:' . $currency->add($numberB);
//        echo '<br>Ket qua:' . $currency->sub($numberB);
        echo '<br>Ket qua:' . $currency->div($numberB);
    }
    
    public function mulAction() {
        $numberA = 100.45;
        $numberB = 2300;
        $options = array('precision'=>3);
        
        $currency = New Zend_Currency($options);
        echo '<br>' . $currency->setValue($numberA);
        
        echo '<br>Ket qua:' . $currency->mul($numberB);
    }
    
    public function modAction() {
        $numberA = 230.45;
        $numberB = 22;
        $options = array('precision'=>3);
        
        $currency = New Zend_Currency($options);
        echo '<br>' . $currency->setValue($numberA);
        
        echo '<br>Ket qua:' . $currency->mod($numberB);
    }
    
    public function compareAction() {
        echo '<br>' . $numberA = 200.456;
//        echo '<br>' . $numberB = 200.4567;
//        echo '<br>' . $numberB = 200.456;
        echo '<br>' . $numberB = 200.455;
        $options = array('precision'=>3);
        
        $currency = New Zend_Currency($options);
        $currency->setValue($numberA);
        
        echo '<br>Ket qua:' . $currency->compare($numberB);
    }
    
    public function equalsAction() {
        echo '<br>' . $numberA = 200.456;
        echo '<br>' . $numberB = 200.456;
        
        $currency = New Zend_Currency();
        $currency->setValue($numberA);
        if($currency->equals($numberB)){
            echo '<br> 2 gia tri bang nhau';
        }
    }
    
    public function moreAction() {
        echo '<br>' . $numberA = 200.456;
        echo '<br>' . $numberB = 200.456;
        
        $currency = New Zend_Currency();
        $currency->setValue($numberA);
        
        if($currency->isMore($numberB) == false){
            echo '<br> So B >= so A';
        }
        
        if($currency->isLess($numberB) == false){
            echo '<br> So B =< so A';
        }
    }
    
    public function getAction() {
        $currency = New Zend_Currency();
//        $tmp = $currency->getCurrencyList();
//        $tmp = $currency->getLocale();
//        $tmp = $currency->getSymbol(null ,'en_US');
//        $tmp = $currency->getShortName(null ,'de_DE');
        $tmp = $currency->getName('vi_VN');
        echo '<pre>';
        print_r($tmp);
        echo '<pre>';
    }
}